package com.example.administrator.printoutindemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;


public class StoreSubmitProject3Adapter extends BaseAdapter {
    private Context mContext = null;
    private List<OutStorageList> li_info = null;
    private OutStorageList oli = null;
    private LayoutInflater mInflater = null;


    private class ViewHolder {
        TextView s_sub3_txt_title;
        TextView s_sub3_ada_edx_outcount;
        TextView tv_bian_ma;
        TextView tv_dan_wei;
    }

    private ViewHolder holder = null;

    public StoreSubmitProject3Adapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setList(List<OutStorageList> li_info) {
        this.li_info = li_info;
        this.mInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);


    }


    @Override
    public int getCount() {
        int result = 0;
        if (null != li_info) {
            result = li_info.size();
        }
        return result;
    }

    @Override
    public Object getItem(int position) {
        Object result = null;
        if (null != li_info) {
            result = li_info.get(position);
        }

        return result;
    }

    @Override
    public long getItemId(int position) {
        int result = 0;
        if (null != li_info) {
            //result = Integer.parseInt(mData.get(position).get("list_item_mid").toString());
            result = position;
        }
        return result;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {

            holder = new ViewHolder();

            convertView = mInflater.inflate(
                    R.layout.store_adapter_sub3_outstorage, null);

            holder.s_sub3_txt_title = (TextView) convertView.findViewById(R.id.s_sub3_txt_title);
            holder.s_sub3_ada_edx_outcount = (TextView) convertView.findViewById(R.id.s_sub3_ada_edx_outcount);
            holder.tv_bian_ma = (TextView) convertView.findViewById(R.id.tv_bian_ma);
            holder.tv_dan_wei = (TextView) convertView.findViewById(R.id.tv_dan_wei);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (null != this.li_info) {

            OutStorageList ol = li_info.get(position);

            String materailInfo = ol.get_materialInfo();

//			materailInfo = materailInfo.substring(0,materailInfo.lastIndexOf("剩余数量"));

            holder.s_sub3_ada_edx_outcount.setText("出库数量：" + ol.get_out_storage_count());
            holder.s_sub3_txt_title.setText(materailInfo);
            holder.tv_bian_ma.setText(ol.getMaterialCode());
            holder.tv_dan_wei.setText(ol.getUnit());

        }


        return convertView;
    }

}